package com.dgut.service;

import io.jsonwebtoken.Claims;
import org.springframework.security.core.userdetails.User;

import javax.servlet.http.HttpServletRequest;
import java.util.Optional;

public interface TokenService {

    /**
     * 根据User创建AccessToken
     * @param user
     * @return
     */
    public String createAccessToken(User user);

    /**
     * 获取请求request中的accessToken
     * @param request
     * @return accessToken
     */
    public String getAccessToken(HttpServletRequest request);

    /**
     * 解析accessToken
     * @param accessToken
     * @return
     */
    public Optional<Claims> getUserByAccessToken(String accessToken);

    /**
     * 根据accessToken获取UserName
     * @param accessToken
     * @return UserName
     */
    public String getUserNameByAccessToken(String accessToken);

    public Boolean isAccessTokenValid(String accessToken);
}
